﻿using JustMetClient.Commons;
using JustMetClient.Models.ConfigModels;
using Azylee.Core.DataUtils.CollectionUtils;
using Azylee.YeahWeb.HttpUtils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JustMetClient.Modules.WebConfigModule
{
    public class WebConfigHelper
    {
        public static void Read()
        {
            //同步配置信息
            List<WebConfigModel> web_configs = HttpTool.Get<List<WebConfigModel>>(R.Config.WEB_CONFIG_API);
            if (ListTool.HasElements(web_configs)) R.Config.WebConfigs = web_configs;

            //加载策略断网开关
            try
            {
                WebConfigModel STRATEGY_DISCONNECT_NET = R.Config.WebConfigs.FirstOrDefault(x => x.type == "STRATEGY" && x.item == "STRATEGY_DISCONNECT_NET");
                if (STRATEGY_DISCONNECT_NET != null) R.Flag.StrategyDisconnectNet = STRATEGY_DISCONNECT_NET.value == "true" ? true : false;
            }
            catch { }

            //加载自动弹框开关
            try
            {
                WebConfigModel FLAG_TOAST_AUTOSHOW = R.Config.WebConfigs.FirstOrDefault(x => x.type == "FLAG" && x.item == "FLAG_TOAST_AUTOSHOW");
                if (FLAG_TOAST_AUTOSHOW != null) R.Flag.AutoShow = FLAG_TOAST_AUTOSHOW.value == "true" ? true : false;
            }
            catch { }
        }
    }
}
